/**
 * this file use to handle common function on list page
 * 
 * 
 */

$(document).ready(function() {
	setSeachCalender()

});

function setSeachCalender() {
	$(".datepicker").datepicker({
		dateFormat : "dd/mm/yy"
	});

}

function confirmAndDelete(element) {

	if (confirm('Do you really want to delete this record ? Once you do it, this opperation cannot be undone !')) {
		var url = $(element).attr("lang");
		console.info("############ url :" + url);
		if (url != null) {
			window.location = url;
		} else {
			return false;
		}
	}
}

function selectAll() {
	console.log('t', isChecked('selectAll'))
	$('.selectedId').prop('checked', isChecked('selectAll'));
}

function isChecked(checkboxId) {
	var id = '#' + checkboxId;
	return $(id).is(":checked");
}

function selectedDelete() {
	chkBoxCount = $('input[type="checkbox"]:checked').length;
	if (chkBoxCount > 0)
		$('#selectedDelete').removeAttr('disabled');
}

function resetSelectAll() {
	// if all checkbox are selected, check the selectall checkbox
	// and viceversa
	if ($(".selectedId").length == $(".selectedId:checked").length) {
		$("#selectAll").attr("checked", "checked");
	} else {
		$("#selectAll").removeAttr("checked");
	}
}

function resetSearchBtn() {
	$("#reset_btn").on("click ", function() {
		$(".searchSelector").val("");
		if ($('.searchSelector').is(':empty')) {
			$("#form_id").submit();
		}

	});
}

function paginationNextBtn(baseUrl) {
	if (baseUrl != null) {
		$('#pageNum').on('keypress', function(event) {
			if (event.which == '13') {
				var url = baseUrl + $(this).val();
				document.location = url;
			}
		});
	}
}

/*function deleteFiltered(deleteItem) {
	var proceed = confirm("Are you sure, you want to delete the searched dataset ? If you select yes, the operation cannot be undone");
	if (proceed) {
		var baseUrl = "${pageContext.request.contextPath}/admin/" + deleteItem
				+ "/deleteFiltered.html";
		document.location = baseUrl;
	}

	return proceed;
}*/